package com.hzit.controller;

import com.hzit.entity.R;
import com.hzit.entity.Specification;
import com.hzit.entity.SpecificationOption;
import com.hzit.service.SpecificationOptionService;
import com.hzit.service.SpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@Controller
@RequestMapping("/specification")
public class SpecificationController {
	@Autowired
	private SpecificationService specificationService;
	@Autowired
	private SpecificationOptionService optionService;

	//1. 列表所有规格
	@RequestMapping("/list")
	@ResponseBody
	public R findAll(){
		List<Specification> specifications =  specificationService.findAll();
		return R.ok().put("specifications",specifications);
	}

	//2. 根据规格id查询规格选项列表
	@RequestMapping("/findOptionsBySpecId")
	@ResponseBody
	public R findOptionsBySpecId(Long specId){
		List<SpecificationOption> options = optionService.findOptionsBySpecId(specId);
		return R.ok().put("options",options);
	}
}
